# coding=utf-8

import scrapy

"""
    登录策略三: 直接使用保存的登录状态的Cookie进行模拟登录
"""

class Renren3Spider(scrapy.Spider):
    name = "renren3"
    allow_domains=["renren.com"]
    start_urls = [
        "http://blog.renren.com/blog/967677932/myBlogs",
        "http://www.renren.com/967677932/profile?v=info_timeline",
        # ,
    ]

    cookies = {
        "anonymid" : "jl4hifwap7nggv",
        "depovince" : "GW",
        "_r01_" : "1",
        "ick_login" : "b341a0bb - e078 - 4f5f - a428 - d2239643db6a",
        "ick" : "9e07ba70 - 7e78 - 4be1 - b2a4 - c8d92421e91e",
        "__utma" : "151146938.1416465008.1534902857.1534902857.1534902857.1",
        "__utmc" : "151146938",
        "__utmz" : "151146938.1534902857.1.1.utmcsr = renren.com | utmccn = (referral) | utmcmd = referral | utmcct = /",
        "jebe_key" : "fc4138ec - 11f2 - 4a6d - 80ba - 3c2b6d2cb81a % 7Cc6d00dfe3c90ccc98d67d93fdfa61df6 % 7C1534902880788 % 7C1 % 7C1534902889900",
        "XNESSESSIONID" : "a26cd3f365e6",
        "__utmb" : "151146938.5.10.1534902857",
        "first_login_flag" : "1",
        "ln_uact" : "17612153143",
        "ln_hurl" : "http: // head.xiaonei.com / photos / 0 / 0 / men_main.gif",
        "jebecookies" : "db605a0e - 6e58 - 47fa - 8371 - c2e6cac50716 | | | | |",
        "_de" : "2E46ED3D6F592B87AA5A391A6A10E115",
        "p" : "4f9cc9db77b83548233673990c57e7f12",
        "t" : "8162ff634a19a37cca274621f0e1e26b2",
        "societyguester" : "8162ff634a19a37cca274621f0e1e26b2",
        "id" : "967677932",
        "xnsid" : "a092cb83",
        "ver" : "7.0",
        "loginfrom" : "null",
        "wp_fold" : "0"
    }

    def start_requests(self):
        for url in self.start_urls:
            yield scrapy.FormRequest(url, cookies=self.cookies, callback=self.parse_page)

    def parse_page(self, response):
        with open("deng.html", "w") as file:
            file.write(response.body)